library(tidyverse)
library(estimatr)
library(haven)

### TABLE G1 ###

setwd("~/Dropbox/GuessNyhanReifler/DART0023/PNAS/post_accept/replication files/US data")

w1 <- read_dta("US_data_clean_w1_headline.DTA")
w1$tips <- as_factor(w1$tips)

w1 <- w1 %>% mutate(type = case_when(dv %in% c(1:2, 5:6) ~ "Hyperpartisan",
                                     dv %in% c(9:10, 13:14) ~ "Mainstream news - low prominence",
                                     dv %in% c(11:12, 15:16) ~ "Mainstream news - high prominence",
                                     TRUE ~ "False news"))

w1 %>% split(.$type) %>%
  map(~ lm_robust(binary_accuracy ~ 0 + tips, clusters = caseid, data = .x)) %>% map_df(tidy, .id = "subgroup") %>%
  mutate(tips = str_replace(term, "tips", "")) %>% select(tips, subgroup, estimate, conf.low, conf.high)

